package com.xoa.controller.enterpriseWeChat;

import com.xoa.model.department.Department;
import com.xoa.model.dingdingManage.DingdingUpdateDept;
import com.xoa.model.enterpriseWeChat.EnterpriseWeChatUpdateDept;
import com.xoa.service.enterpriseWeChat.EnterpriseWeChatService;
import com.xoa.util.ToJson;
import com.xoa.util.common.wrapper.BaseWrapper;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by 桂静文 on 2018/3/22.
 * 企业微信企业号
 */
@Controller
@RequestMapping("/enterpriseWeChatManage")
public class EnterpriseWeChatController {
    @Autowired
    EnterpriseWeChatService enterpriseWeChatService;
    //设置企业微信基础参数
    @ResponseBody
    @RequestMapping("/baseEnterpriseWeChatSetting")
    public BaseWrapper baseEnterpriseWeChatSetting(String oaUrl, String corpId, String corpSecret){
        return enterpriseWeChatService.baseEnterpriseWeChatSetting(oaUrl,corpId,corpSecret);
    }
    //获取企业微信基础参数
    @ResponseBody
    @RequestMapping("/baseEnterpriseWeChatGet")
    public BaseWrapper baseEnterpriseWeChatGet() {
        return enterpriseWeChatService.baseEnterpriseWeChatGet();
    }

    //企业微信连接测试
    @RequestMapping("/enterpriseWeChatConnect")
    public void enterpriseWeChatConnect(HttpServletResponse response, String dingUrl, String dingRequest) throws JSONException {
        enterpriseWeChatService.enterpriseWeChatConnect(response, dingUrl, dingRequest);
    }

    //获取oa部门列表
    @ResponseBody
    @RequestMapping("/enterpriseWeChatGetDeptList")
    public BaseWrapper enterpriseWeChatGetDeptList(Integer deptId) {
        return enterpriseWeChatService.enterpriseWeChatGetDeptList(deptId);
    }

    //获取部门用户列表
    @ResponseBody
    @RequestMapping("/enterpriseWeChatGetUserList")
    public ToJson<Department> enterpriseWeChatGetUserList(Integer deptId) {
        return enterpriseWeChatService.enterpriseWeChatGetUserList(deptId);
    }

    //企业微信组织结构同步
    @ResponseBody
    @RequestMapping("/enterpriseWeChatDeptSynchro")
    public BaseWrapper enterpriseWeChatDeptSynchro() throws JSONException {
        return enterpriseWeChatService.enterpriseWeChatDeptSynchro();
    }

    //企业微信用户管理同步
    @ResponseBody
    @RequestMapping("/enterpriseWeChatUserSynchro")
    public BaseWrapper enterpriseWeChatUserSynchro(String synchroUsers) throws JSONException {
        return enterpriseWeChatService.enterpriseWeChatUserSynchro(synchroUsers);
    }

    //获取企业微信人员列表
    @ResponseBody
    @RequestMapping("/getEnterpriseWeChatUserList")
    public BaseWrapper getEnterpriseWeChatUserList() throws JSONException {
        return enterpriseWeChatService.getEnterpriseWeChatUserList();
    }

    //企业微信账号与OA账号绑定与解除绑定，type为0：绑定，type为1：解除绑定
    @ResponseBody
    @RequestMapping("/bindEnterpriseWeChatAndOA")
    public BaseWrapper bindEnterpriseWeChatAndOA(String dingdingId, String uid, Integer type) {
        return enterpriseWeChatService.bindEnterpriseWeChatAndOA(dingdingId, uid, type);
    }

    //获取企业微信应用
    @ResponseBody
    @RequestMapping("/getEnterpriseWeChatApp")
    public BaseWrapper getEnterpriseWeChatApp(String appName) {
        return enterpriseWeChatService.getEnterpriseWeChatApp(appName);
    }

    //企业微信应用设置
    @ResponseBody
    @RequestMapping("/enterpriseWeChatAppSetting")
    public BaseWrapper enterpriseWeChatAppSetting(String appName, String appId) {
        return enterpriseWeChatService.enterpriseWeChatAppSetting(appName, appId);
    }

    //企业微信组织架构管理获取部门列表
    @ResponseBody
    @RequestMapping("/enterpriseWeChatDepSettingGet")
    public void enterpriseWeChatDepSettingGet(HttpServletResponse response, Integer deptId) {
        enterpriseWeChatService.enterpriseWeChatDepSettingGet(response, deptId);
    }

    //企业微信组织架构管理编辑部门
    @ResponseBody
    @RequestMapping("/enterpriseWeChatDepSettingEdit")
    public BaseWrapper enterpriseWeChatDepSettingEdit(EnterpriseWeChatUpdateDept enterpriseWeChatUpdateDept) {
        return enterpriseWeChatService.enterpriseWeChatDepSettingEdit(enterpriseWeChatUpdateDept);
    }

    //企业微信组织架构管理删除部门
    @ResponseBody
    @RequestMapping("/enterpriseWeChatDepSettingDelete")
    public BaseWrapper dingdingDepSettingDelete(Integer deptId) {
        return enterpriseWeChatService.enterpriseWeChatDepSettingDelete(deptId);
    }

    //企业微信组织架构管理获取编辑页面下拉菜单
    @ResponseBody
    @RequestMapping("/enterpriseWeChatDepSettingMenu")
    public BaseWrapper enterpriseWeChatDepSettingMenu() {
        return enterpriseWeChatService.enterpriseWeChatDepSettingMenu();
    }

    //企业微信免登码获取用户身份
    @ResponseBody
    @RequestMapping("/enterpriseWeChatCodeGetUser")
    public BaseWrapper enterpriseWeChatCodeGetUser(HttpServletRequest request, HttpServletResponse response, String corpId, String corpSecret, String code, String oId) throws JSONException {
        return enterpriseWeChatService.enterpriseWeChatCodeGetUser(request, response, corpId, corpSecret, code, oId);
    }



    //企业微信企业号设置
    @RequestMapping("/getWechatEnterpriseSetting")
    public String getWechatEnterpriseSetting() {
        return "/app/enterpriseWeChatManage/wechatEnterpriseSetting";
    }
    //企业号设置
    @RequestMapping("/getWechatIndex")
    public String getWechatIndex() {
        return "/app/enterpriseWeChatManage/wechatIndex";
    }
    //基础参数设置
    @RequestMapping("/getWechatArameterSetting")
    public String getWechatArameterSetting() {
        return "/app/enterpriseWeChatManage/wechatArameterSetting";
    }
    //同步部门
    @RequestMapping("/getWechatDataImport")
    public String getWechatDataImport() {
        return "/app/enterpriseWeChatManage/wechatDataImport";
    }
    //数据导入 - 组织架构初始化
    @RequestMapping("/getWechatChooseDepartment")
    public String getWechatChooseDepartment() {
        return "/app/enterpriseWeChatManage/wechatChooseDepartment";
    }
    //数据导入 - 人员和日志
    @RequestMapping("/getWechatImportPersonnel")
    public String getWechatImportPersonnel() {
        return "/app/enterpriseWeChatManage/wechatImportPersonnel";
    }
    //数据导入 - 人员
    @RequestMapping("/getWechatImportPeople")
    public String getWechatImportPeople() {
        return "/app/enterpriseWeChatManage/wechatImportPeople";
    }
    //公告通知
    @RequestMapping("/getWechatPublicNotice")
    public String getWechatPublicNotice() {
        return "/app/enterpriseWeChatManage/wechatPublicNotice";
    }
    //导入日志
    @RequestMapping("/getWechatImportLogs")
    public String getWechatImportLogs() {
        return "/app/enterpriseWeChatManage/wechatImportLogs";
    }
    //企业微信组织架构管理
    @RequestMapping("/getWechatOrganizationManagement")
    public String getWechatOrganizationManagement() {
        return "/app/enterpriseWeChatManage/wechatOrganizationManagement";
    }
    //OA用户绑定
    @RequestMapping("/getWechatOaBinding")
    public String getWechatOaBinding() {
        return "/app/enterpriseWeChatManage/wechatOaBinding";
    }
    //组织架构管理
    @RequestMapping("/getWechatOrganizationalStructure")
    public String getWechatOrganizationalStructure() {
        return "/app/enterpriseWeChatManage/wechatOrganizationalStructure";
    }



}
